﻿using System;

namespace NodeJS
{
    using NodeJS.dns;

    public abstract class DNS
    {
        /// <summary>
        /// Resolves a domain (e.g. 'google.com') into the first found A (IPv4) or AAAA (IPv6) record.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback">The callback has arguments (err, address, family). The address argument is a string representation of a IP v4 or v6 address. The family argument is either the integer 4 or 6 and denotes the family of address (not necessarily the value initially passed to lookup).
        /// <para>On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOENT' not only when the domain does not exist but also when the lookup fails in other ways such as no available file descriptors.
        /// On error, err is an Error object, where err.code is one of the error codes listed below.
        /// </para>
        /// </param>
        /// <returns></returns>
        public abstract void Lookup(string domain, Action<DnsException, string, int> callback);

        /// <summary>
        /// Resolves a domain (e.g. 'google.com') into the first found A (IPv4) or AAAA (IPv6) record.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="family">The family can be the integer 4 or 6. Defaults to null that indicates both Ip v4 and v6 address family.</param>
        /// <param name="callback">The callback has arguments (err, address, family). The address argument is a string representation of a IP v4 or v6 address. The family argument is either the integer 4 or 6 and denotes the family of address (not necessarily the value initially passed to lookup).
        /// <para>On error, err is an Error object, where err.code is the error code. Keep in mind that err.code will be set to 'ENOENT' not only when the domain does not exist but also when the lookup fails in other ways such as no available file descriptors.
        /// On error, err is an Error object, where err.code is one of the error codes listed below.
        /// </para>
        /// </param>
        /// <returns></returns>
        public abstract void Lookup(string domain, int? family, Action<DnsException, string, int> callback);


        /// <summary>
        /// Resolves a domain (e.g. 'google.com') into an array of the record types.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback">The callback has arguments (err, addresses). The type of each item in addresses is determined by the record type, and described in the documentation for the corresponding lookup methods below.
        /// On error, err is an Error object, where err.code is one of the error codes listed below.
        /// </param>
        public abstract void Resolve(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// Resolves a domain (e.g. 'google.com') into an array of the record types specified by rrtype.
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="rrtype">Valid rrtypes are:
        /// <para>'A' (IPV4 addresses, default)</para>
        /// <para>'AAAA' (IPV6 addresses)</para>
        /// <para>'MX' (mail exchange records)</para>
        /// <para>'TXT' (text records)</para>
        /// <para>'SRV' (SRV records)</para>
        /// <para>'PTR' (used for reverse IP lookups)</para>
        /// <para>'NS' (name server records)</para>
        /// <para>'CNAME' (canonical name records)</para>
        /// </param>
        /// <param name="callback">The callback has arguments (err, addresses). The type of each item in addresses is determined by the record type, and described in the documentation for the corresponding lookup methods below.
        /// On error, err is an Error object, where err.code is one of the error codes listed below.
        /// </param>
        public abstract void Resolve(string domain, string rrtype, Action<DnsException, string[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for IPv4 queries (A records). addresses is an array of IPv4 addresses (e.g. ['74.125.79.104', '74.125.79.105', '74.125.79.106']).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void Resolve4(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// The same as dns.resolve4() except for IPv6 queries (an AAAA query).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void Resolve6(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for mail exchange queries (MX records).
        /// addresses is an array of MX records, each with a priority and an exchange attribute (e.g. [{'priority': 10, 'exchange': 'mx.example.com'},...]).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void ResolveMx(string domain, Action<DnsException, MxRecord[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for text queries (TXT records). addresses is an array of the text records available for domain (e.g., ['v=spf1 ip4:0.0.0.0 ~all']).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void ResolveTxt(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for service records (SRV records). addresses is an array of the SRV records available for domain. Properties of SRV records are priority, weight, port, and name (e.g., [{'priority': 10, 'weight': 5, 'port': 21223, 'name': 'service.example.com'}, ...]).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void ResolveSrv(string domain, Action<DnsException, SrvRecord[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for name server records (NS records). addresses is an array of the name server records available for domain (e.g., ['ns1.example.com', 'ns2.example.com']).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void ResolveNs(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// The same as dns.resolve(), but only for canonical name records (CNAME records). addresses is an array of the canonical name records available for domain (e.g., ['bar.example.com']).
        /// </summary>
        /// <param name="domain"></param>
        /// <param name="callback"></param>
        public abstract void ResolveCname(string domain, Action<DnsException, string[]> callback);

        /// <summary>
        /// Reverse resolves an ip address to an array of domain names.
        /// </summary>
        /// <param name="ip"></param>
        /// <param name="callback">The callback has arguments (err, domains).
        /// On error, err is an Error object, where err.code is one of the error codes listed below.
        /// </param>
        public abstract void Reverse(string ip, Action<DnsException, string[]> callback);

        /// <summary>
        /// DNS server returned answer with no data.
        /// </summary>
        public readonly int NODATA;

        /// <summary>
        /// DNS server claims query was misformatted.
        /// </summary>
        public readonly int FORMERR;

        /// <summary>
        /// DNS server returned general failure.
        /// </summary>
        public readonly int SERVFAIL;

        /// <summary>
        /// Domain name not found.
        /// </summary>
        public readonly int NOTFOUND;

        /// <summary>
        /// DNS server does not implement requested operation.
        /// </summary>
        public readonly int NOTIMP;

        /// <summary>
        /// DNS server refused query.
        /// </summary>
        public readonly int REFUSED;

        /// <summary>
        /// Misformatted DNS query.
        /// </summary>
        public readonly int BADQUERY;

        /// <summary>
        /// Misformatted domain name.
        /// </summary>
        public readonly int BADNAME;

        /// <summary>
        /// Unsupported address family.
        /// </summary>
        public readonly int BADFAMILY;

        /// <summary>
        /// Misformatted DNS reply.
        /// </summary>
        public readonly int BADRESP;

        /// <summary>
        /// Could not contact DNS servers.
        /// </summary>
        public readonly int CONNREFUSED;

        /// <summary>
        /// Timeout while contacting DNS servers.
        /// </summary>
        public readonly int TIMEOUT;

        /// <summary>
        /// End of file.
        /// </summary>
        public readonly int EOF;

        /// <summary>
        /// Error reading file.
        /// </summary>
        public readonly int FILE;

        /// <summary>
        /// Out of memory.
        /// </summary>
        public readonly int NOMEM;

        /// <summary>
        /// Channel is being destroyed.
        /// </summary>
        public readonly int DESTRUCTION;

        /// <summary>
        /// Misformatted string.
        /// </summary>
        public readonly int BADSTR;

        /// <summary>
        /// Illegal flags specified.
        /// </summary>
        public readonly int BADFLAGS;

        /// <summary>
        /// Given hostname is not numeric.
        /// </summary>
        public readonly int NONAME;

        /// <summary>
        /// Illegal hints flags specified.
        /// </summary>
        public readonly int BADHINTS;

        /// <summary>
        /// c-ares library initialization not yet performed.
        /// </summary>
        public readonly int NOTINITIALIZED;

        /// <summary>
        /// Error loading iphlpapi.dll.
        /// </summary>
        public readonly int LOADIPHLPAPI;

        /// <summary>
        /// Could not find GetNetworkParams function.
        /// </summary>
        public readonly int ADDRGETNETWORKPARAMS;

        /// <summary>
        /// DNS query cancelled.
        /// </summary>
        public readonly int CANCELLED;
    }
}
